package com.seven.good.service.impl;

import com.seven.good.dao.GoodTypeMapper;
import com.seven.good.exception.ServiceException;
import com.seven.good.pojo.GoodType;
import com.seven.good.service.GoodTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class GoodTypeServiceImpl implements GoodTypeService {
    @Autowired
    GoodTypeMapper goodTypeMapper;

    @Override
    @Cacheable(value ="goodType", key = "'type'+#gtid")
    public GoodType getGoodTypeByGtid(Integer gtid) throws ServiceException{
        GoodType goodType = null;
        try {
            goodType = goodTypeMapper.selectByPrimaryKey(gtid);
        } catch (Exception e) {
            e.printStackTrace();
            throw new ServiceException("数据库查询异常");
        }
        return goodType;
    }

    @Override
    @Cacheable(value ="goodType", key = "'list'")
    public List<GoodType> listAllGoodTypes() throws ServiceException{
        System.out.println("----->");
        List<GoodType> goodTypes = null;
        try {
            goodTypes = goodTypeMapper.selectAllGoodTypes();
            System.out.println("goodTypes"+goodTypes);
        } catch (Exception e) {
            e.printStackTrace();
            throw new ServiceException("数据库查询异常");
        }
        return goodTypes;
    }
}
